package com.telenav.snowsweeper.data;

import com.telenav.snowsweeper.renderer.Util;

public class PointsManager {
	private static Point[][] points;  
	static 
	{
	    PointsManager.init(Util.ROW + 1, Util.COLUMN + 1);
	}
	public static void init(int row, int col) {
		points = new Point[row][col];
		int x = 0;
		int y = 0;
		for (int i = 0; i < row; ++i) {
			for (int j = 0; j < col; ++j) {
				points[i][j] = new Point(x, y);
				x += Util.SQUARE_NORMALIZED_SIZE;
			}
			x = 0;
			y += Util.SQUARE_NORMALIZED_SIZE;
		}
	}
	
	public static Point getPoint(int row, int col) {
		if (row < 0 || row >= points.length)
			return null;
		if (col < 0 || col >= points[row].length)
			return null;
		return points[row][col];
	}
	
	public static Point getLeftPointIfHave(Point point) {
		Point r = getPoint(point.getRow(), point.getColumn() - 1);
		return r != null ? r : point;
	}
	
	public static Point getRightPointIfHave(Point point) {
		Point r = getPoint(point.getRow(), point.getColumn() + 1);
		return r != null ? r : point;
	}

	public static Point getTopPointIfHave(Point point) {
		Point r = getPoint(point.getRow() - 1, point.getColumn());
		return r != null ? r : point;
	}

	public static Point getBottomPointIfHave(Point point) {
		Point r = getPoint(point.getRow() + 1, point.getColumn());
		return r != null ? r : point;
	}
}
